<!DOCTYPE html>
<!-- saved from url=(0184)file:///D:/%E5%B7%A5%E4%BD%9C/%E8%81%94%E5%90%88%E8%B5%84%E4%BF%A1/cdo/%E4%BF%A1%E7%94%A8%E8%AF%84%E7%BA%A7%E8%BF%9D%E7%BA%A6%E7%8E%87%E6%8F%92%E5%80%BC%E8%AE%A1%E7%AE%97%E5%99%A8.html -->
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信用评级违约率插值计算器</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Arial, sans-serif;
        }
        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }
        .container {
            max-width: 1400px;
            margin: 0 auto;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            padding: 25px;
        }
        header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid #eaeaea;
        }
        h1 {
            color: #2c3e50;
            margin-bottom: 10px;
        }
        .description {
            color: #7f8c8d;
            max-width: 800px;
            margin: 0 auto;
        }
        .calculator {
            display: flex;
            flex-wrap: wrap;
            gap: 30px;
            margin-bottom: 30px;
        }
        .input-section {
            flex: 1;
            min-width: 300px;
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        }
        .result-section {
            flex: 2;
            min-width: 300px;
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: 600;
            color: #2c3e50;
        }
        input, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            transition: background-color 0.3s;
            width: 100%;
        }
        button:hover {
            background-color: #2980b9;
        }
        .result-item {
            padding: 15px;
            background-color: white;
            border-radius: 6px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        .result-title {
            font-weight: 600;
            margin-bottom: 5px;
            color: #2c3e50;
            font-size: 14px;
        }
        .result-value {
            font-size: 18px;
            color: #3498db;
        }
        .table-container {
            overflow-x: auto;
            margin-top: 20px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        th, td {
            padding: 12px 15px;
            text-align: center;
            border: 1px solid #e0e0e0;
        }
        th {
            background-color: #2c3e50;
            color: white;
            font-weight: 600;
            position: sticky;
            top: 0;
        }
        tr:nth-child(even) {
            background-color: #f8f9fa;
        }
        tr:hover {
            background-color: #eef5ff;
        }
        .highlight {
            background-color: #fffacd !important;
        }
        .footer {
            text-align: center;
            margin-top: 30px;
            color: #7f8c8d;
            font-size: 14px;
        }
        @media (max-width: 768px) {
            .calculator {
                flex-direction: column;
            }
            .result-section {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>信用评级违约率插值计算器</h1>
            <p class="description">根据期限计算违约率插值。输入期限和违约率值，计算相邻期限下的插值违约率，并显示对应的信用评级。</p>
        </header>

        <div class="calculator">
            <div class="input-section">
                <h2>插值计算</h2>
                <div class="form-group">
                    <label for="life">期限 (年):</label>
                    <input type="number" id="life" min="1" max="10" step="0.1" value="1.81">
                </div>
                <div class="form-group">
                    <label for="defaultRateValue">违约率:</label>
                    <input type="number" id="defaultRateValue" min="0" max="1" step="0.000001" value="0.00444">
                </div>
                <button id="calculateBtn">计算插值</button>
            </div>

            <div class="result-section">
                <div class="result-item">
                    <div class="result-title">插值违约率:</div>
                    <div class="result-value" id="interpolatedDefaultRate">0.0042</div>
                </div>
                <div class="result-item">
                    <div class="result-title">下限期限:</div>
                    <div class="result-value" id="floorLife">1</div>
                </div>
                <div class="result-item">
                    <div class="result-title">上限期限:</div>
                    <div class="result-value" id="ceilLife">2</div>
                </div>
                <div class="result-item">
                    <div class="result-title">下限违约率:</div>
                    <div class="result-value" id="floorDefaultRate">0.0015</div>
                </div>
                <div class="result-item">
                    <div class="result-title">上限违约率:</div>
                    <div class="result-value" id="ceilDefaultRate">0.0050</div>
                </div>
                <div class="result-item">
                    <div class="result-title">对应评级:</div>
                    <div class="result-value" id="correspondingRank">A+</div>
                </div>
                <div class="result-item">
                    <div class="result-title">评级拼接:</div>
                    <div class="result-value" id="rankConcatenation">AA-/A+</div>
                </div>
            </div>
        </div>

        <div class="table-container">
            <h2>违约率数据表</h2>
            <table id="defaultRateTable">
                <thead>
                    <tr>
                        <th>期限</th>
                        <th>AAA+</th>
                        <th>AAA</th>
                        <th>AAA-</th>
                        <th>AA+</th>
                        <th>AA</th>
                        <th>AA-</th>
                        <th>A+</th>
                        <th>A</th>
                        <th>A-</th>
                        <th>BBB+</th>
                        <th>BBB</th>
                        <th>BBB-</th>
                        <th>BB+</th>
                        <th>BB</th>
                        <th>BB-</th>
                        <th>B+</th>
                        <th>B</th>
                        <th>B-</th>
                        <th>CCC</th>
                        <th>CC</th>
                        <th>C</th>
                        <th>D</th>
                    </tr>
                </thead>
                <tbody id="tableBody"><tr class="highlight"><td style="font-weight: bold;">1</td><td>0.0001</td><td>0.0001</td><td>0.0003</td><td>0.0005</td><td>0.0007</td><td>0.0010</td><td>0.0015</td><td>0.0020</td><td>0.0030</td><td>0.0060</td><td>0.0081</td><td>0.0100</td><td>0.0130</td><td>0.0200</td><td>0.0400</td><td>0.0600</td><td>0.1800</td><td>0.2600</td><td>0.4300</td><td>0.6100</td><td>0.8530</td><td>1.0000</td></tr><tr class="highlight"><td style="font-weight: bold;">2</td><td>0.0001</td><td>0.0002</td><td>0.0004</td><td>0.0010</td><td>0.0013</td><td>0.0020</td><td>0.0050</td><td>0.0065</td><td>0.0100</td><td>0.0145</td><td>0.0250</td><td>0.0300</td><td>0.0400</td><td>0.0600</td><td>0.1100</td><td>0.1700</td><td>0.3500</td><td>0.4700</td><td>0.6400</td><td>0.8000</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">3</td><td>0.0003</td><td>0.0006</td><td>0.0012</td><td>0.0022</td><td>0.0027</td><td>0.0035</td><td>0.0100</td><td>0.0115</td><td>0.0185</td><td>0.0232</td><td>0.0462</td><td>0.0540</td><td>0.0800</td><td>0.1200</td><td>0.1900</td><td>0.2800</td><td>0.4800</td><td>0.6200</td><td>0.7800</td><td>0.9000</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">4</td><td>0.0005</td><td>0.0010</td><td>0.0019</td><td>0.0045</td><td>0.0053</td><td>0.0065</td><td>0.0150</td><td>0.0165</td><td>0.0300</td><td>0.0347</td><td>0.0653</td><td>0.0800</td><td>0.1200</td><td>0.1700</td><td>0.2600</td><td>0.3700</td><td>0.5600</td><td>0.7200</td><td>0.8700</td><td>0.9700</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">5</td><td>0.0011</td><td>0.0020</td><td>0.0029</td><td>0.0060</td><td>0.0070</td><td>0.0085</td><td>0.0200</td><td>0.0216</td><td>0.0390</td><td>0.0470</td><td>0.0838</td><td>0.1100</td><td>0.1500</td><td>0.2100</td><td>0.3200</td><td>0.4300</td><td>0.6300</td><td>0.7800</td><td>0.9200</td><td>0.9900</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">6</td><td>0.0025</td><td>0.0035</td><td>0.0044</td><td>0.0075</td><td>0.0085</td><td>0.0120</td><td>0.0240</td><td>0.0260</td><td>0.0460</td><td>0.0600</td><td>0.1013</td><td>0.1300</td><td>0.1800</td><td>0.2600</td><td>0.3800</td><td>0.4900</td><td>0.6800</td><td>0.8300</td><td>0.9400</td><td>0.9900</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">7</td><td>0.0035</td><td>0.0045</td><td>0.0054</td><td>0.0090</td><td>0.0100</td><td>0.0150</td><td>0.0270</td><td>0.0300</td><td>0.0520</td><td>0.0700</td><td>0.1152</td><td>0.1500</td><td>0.2100</td><td>0.3000</td><td>0.4200</td><td>0.5300</td><td>0.7100</td><td>0.8700</td><td>0.9700</td><td>0.9900</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">8</td><td>0.0050</td><td>0.0060</td><td>0.0070</td><td>0.0110</td><td>0.0120</td><td>0.0180</td><td>0.0300</td><td>0.0350</td><td>0.0590</td><td>0.0820</td><td>0.1279</td><td>0.1700</td><td>0.2300</td><td>0.3300</td><td>0.4600</td><td>0.5700</td><td>0.7350</td><td>0.9000</td><td>0.9900</td><td>0.9900</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">9</td><td>0.0065</td><td>0.0075</td><td>0.0086</td><td>0.0130</td><td>0.0140</td><td>0.0200</td><td>0.0345</td><td>0.0400</td><td>0.0670</td><td>0.0920</td><td>0.1382</td><td>0.1800</td><td>0.2500</td><td>0.3600</td><td>0.5000</td><td>0.6100</td><td>0.7600</td><td>0.9100</td><td>0.9900</td><td>0.9900</td><td>0.9900</td><td>1.0000</td></tr><tr><td style="font-weight: bold;">10</td><td>0.0080</td><td>0.0090</td><td>0.0104</td><td>0.0150</td><td>0.0175</td><td>0.0235</td><td>0.0380</td><td>0.0452</td><td>0.0721</td><td>0.1000</td><td>0.1462</td><td>0.2000</td><td>0.2700</td><td>0.3800</td><td>0.5300</td><td>0.6400</td><td>0.7800</td><td>0.9200</td><td>0.9900</td><td>0.9900</td><td>0.9900</td><td>1.0000</td></tr></tbody>
            </table>
        </div>

        <div class="footer">
            <p>信用评级违约率插值计算器 © 2023</p>
        </div>
    </div>

    <script>
        // 违约率数据
        const defaultRateData = [
            {"defaultRate":0.0001,"rankCode":"AAA+","life":1},
            {"defaultRate":0.00015,"rankCode":"AAA","life":1},
            {"defaultRate":0.00025,"rankCode":"AAA-","life":1},
            {"defaultRate":0.0005,"rankCode":"AA+","life":1},
            {"defaultRate":0.0007,"rankCode":"AA","life":1},
            {"defaultRate":0.001,"rankCode":"AA-","life":1},
            {"defaultRate":0.0015,"rankCode":"A+","life":1},
            {"defaultRate":0.002,"rankCode":"A","life":1},
            {"defaultRate":0.003,"rankCode":"A-","life":1},
            {"defaultRate":0.006,"rankCode":"BBB+","life":1},
            {"defaultRate":0.0081,"rankCode":"BBB","life":1},
            {"defaultRate":0.01,"rankCode":"BBB-","life":1},
            {"defaultRate":0.013,"rankCode":"BB+","life":1},
            {"defaultRate":0.02,"rankCode":"BB","life":1},
            {"defaultRate":0.04,"rankCode":"BB-","life":1},
            {"defaultRate":0.06,"rankCode":"B+","life":1},
            {"defaultRate":0.18,"rankCode":"B","life":1},
            {"defaultRate":0.26,"rankCode":"B-","life":1},
            {"defaultRate":0.43,"rankCode":"CCC","life":1},
            {"defaultRate":0.61,"rankCode":"CC","life":1},
            {"defaultRate":0.853,"rankCode":"C","life":1},
            {"defaultRate":1,"rankCode":"D","life":1},
            {"defaultRate":0.00011,"rankCode":"AAA+","life":2},
            {"defaultRate":0.0002,"rankCode":"AAA","life":2},
            {"defaultRate":0.00045,"rankCode":"AAA-","life":2},
            {"defaultRate":0.001,"rankCode":"AA+","life":2},
            {"defaultRate":0.0013,"rankCode":"AA","life":2},
            {"defaultRate":0.002,"rankCode":"AA-","life":2},
            {"defaultRate":0.005,"rankCode":"A+","life":2},
            {"defaultRate":0.0065,"rankCode":"A","life":2},
            {"defaultRate":0.01,"rankCode":"A-","life":2},
            {"defaultRate":0.0145,"rankCode":"BBB+","life":2},
            {"defaultRate":0.025,"rankCode":"BBB","life":2},
            {"defaultRate":0.03,"rankCode":"BBB-","life":2},
            {"defaultRate":0.04,"rankCode":"BB+","life":2},
            {"defaultRate":0.06,"rankCode":"BB","life":2},
            {"defaultRate":0.11,"rankCode":"BB-","life":2},
            {"defaultRate":0.17,"rankCode":"B+","life":2},
            {"defaultRate":0.35,"rankCode":"B","life":2},
            {"defaultRate":0.47,"rankCode":"B-","life":2},
            {"defaultRate":0.64,"rankCode":"CCC","life":2},
            {"defaultRate":0.8,"rankCode":"CC","life":2},
            {"defaultRate":0.99,"rankCode":"C","life":2},
            {"defaultRate":1,"rankCode":"D","life":2},
            {"defaultRate":0.00027,"rankCode":"AAA+","life":3},
            {"defaultRate":0.0006,"rankCode":"AAA","life":3},
            {"defaultRate":0.00118,"rankCode":"AAA-","life":3},
            {"defaultRate":0.00222,"rankCode":"AA+","life":3},
            {"defaultRate":0.0027,"rankCode":"AA","life":3},
            {"defaultRate":0.0035,"rankCode":"AA-","life":3},
            {"defaultRate":0.01,"rankCode":"A+","life":3},
            {"defaultRate":0.0115,"rankCode":"A","life":3},
            {"defaultRate":0.0185,"rankCode":"A-","life":3},
            {"defaultRate":0.0232,"rankCode":"BBB+","life":3},
            {"defaultRate":0.0462,"rankCode":"BBB","life":3},
            {"defaultRate":0.054,"rankCode":"BBB-","life":3},
            {"defaultRate":0.08,"rankCode":"BB+","life":3},
            {"defaultRate":0.12,"rankCode":"BB","life":3},
            {"defaultRate":0.19,"rankCode":"BB-","life":3},
            {"defaultRate":0.28,"rankCode":"B+","life":3},
            {"defaultRate":0.48,"rankCode":"B","life":3},
            {"defaultRate":0.62,"rankCode":"B-","life":3},
            {"defaultRate":0.78,"rankCode":"CCC","life":3},
            {"defaultRate":0.9,"rankCode":"CC","life":3},
            {"defaultRate":0.99,"rankCode":"C","life":3},
            {"defaultRate":1,"rankCode":"D","life":3},
            {"defaultRate":0.0005,"rankCode":"AAA+","life":4},
            {"defaultRate":0.00105,"rankCode":"AAA","life":4},
            {"defaultRate":0.0019,"rankCode":"AAA-","life":4},
            {"defaultRate":0.0045,"rankCode":"AA+","life":4},
            {"defaultRate":0.0053,"rankCode":"AA","life":4},
            {"defaultRate":0.0065,"rankCode":"AA-","life":4},
            {"defaultRate":0.015,"rankCode":"A+","life":4},
            {"defaultRate":0.0165,"rankCode":"A","life":4},
            {"defaultRate":0.03,"rankCode":"A-","life":4},
            {"defaultRate":0.0347,"rankCode":"BBB+","life":4},
            {"defaultRate":0.0653,"rankCode":"BBB","life":4},
            {"defaultRate":0.08,"rankCode":"BBB-","life":4},
            {"defaultRate":0.12,"rankCode":"BB+","life":4},
            {"defaultRate":0.17,"rankCode":"BB","life":4},
            {"defaultRate":0.26,"rankCode":"BB-","life":4},
            {"defaultRate":0.37,"rankCode":"B+","life":4},
            {"defaultRate":0.56,"rankCode":"B","life":4},
            {"defaultRate":0.72,"rankCode":"B-","life":4},
            {"defaultRate":0.87,"rankCode":"CCC","life":4},
            {"defaultRate":0.97,"rankCode":"CC","life":4},
            {"defaultRate":0.99,"rankCode":"C","life":4},
            {"defaultRate":1,"rankCode":"D","life":4},
            {"defaultRate":0.0011,"rankCode":"AAA+","life":5},
            {"defaultRate":0.002,"rankCode":"AAA","life":5},
            {"defaultRate":0.0029,"rankCode":"AAA-","life":5},
            {"defaultRate":0.006,"rankCode":"AA+","life":5},
            {"defaultRate":0.007,"rankCode":"AA","life":5},
            {"defaultRate":0.0085,"rankCode":"AA-","life":5},
            {"defaultRate":0.02,"rankCode":"A+","life":5},
            {"defaultRate":0.0216,"rankCode":"A","life":5},
            {"defaultRate":0.039,"rankCode":"A-","life":5},
            {"defaultRate":0.047,"rankCode":"BBB+","life":5},
            {"defaultRate":0.0838,"rankCode":"BBB","life":5},
            {"defaultRate":0.11,"rankCode":"BBB-","life":5},
            {"defaultRate":0.15,"rankCode":"BB+","life":5},
            {"defaultRate":0.21,"rankCode":"BB","life":5},
            {"defaultRate":0.32,"rankCode":"BB-","life":5},
            {"defaultRate":0.43,"rankCode":"B+","life":5},
            {"defaultRate":0.63,"rankCode":"B","life":5},
            {"defaultRate":0.78,"rankCode":"B-","life":5},
            {"defaultRate":0.92,"rankCode":"CCC","life":5},
            {"defaultRate":0.99,"rankCode":"CC","life":5},
            {"defaultRate":0.99,"rankCode":"C","life":5},
            {"defaultRate":1,"rankCode":"D","life":5},
            {"defaultRate":0.0025,"rankCode":"AAA+","life":6},
            {"defaultRate":0.0035,"rankCode":"AAA","life":6},
            {"defaultRate":0.0044,"rankCode":"AAA-","life":6},
            {"defaultRate":0.0075,"rankCode":"AA+","life":6},
            {"defaultRate":0.0085,"rankCode":"AA","life":6},
            {"defaultRate":0.012,"rankCode":"AA-","life":6},
            {"defaultRate":0.024,"rankCode":"A+","life":6},
            {"defaultRate":0.026,"rankCode":"A","life":6},
            {"defaultRate":0.046,"rankCode":"A-","life":6},
            {"defaultRate":0.06,"rankCode":"BBB+","life":6},
            {"defaultRate":0.1013,"rankCode":"BBB","life":6},
            {"defaultRate":0.13,"rankCode":"BBB-","life":6},
            {"defaultRate":0.18,"rankCode":"BB+","life":6},
            {"defaultRate":0.26,"rankCode":"BB","life":6},
            {"defaultRate":0.38,"rankCode":"BB-","life":6},
            {"defaultRate":0.49,"rankCode":"B+","life":6},
            {"defaultRate":0.68,"rankCode":"B","life":6},
            {"defaultRate":0.83,"rankCode":"B-","life":6},
            {"defaultRate":0.94,"rankCode":"CCC","life":6},
            {"defaultRate":0.99,"rankCode":"CC","life":6},
            {"defaultRate":0.99,"rankCode":"C","life":6},
            {"defaultRate":1,"rankCode":"D","life":6},
            {"defaultRate":0.0035,"rankCode":"AAA+","life":7},
            {"defaultRate":0.0045,"rankCode":"AAA","life":7},
            {"defaultRate":0.0054,"rankCode":"AAA-","life":7},
            {"defaultRate":0.009,"rankCode":"AA+","life":7},
            {"defaultRate":0.01,"rankCode":"AA","life":7},
            {"defaultRate":0.015,"rankCode":"AA-","life":7},
            {"defaultRate":0.027,"rankCode":"A+","life":7},
            {"defaultRate":0.03,"rankCode":"A","life":7},
            {"defaultRate":0.052,"rankCode":"A-","life":7},
            {"defaultRate":0.07,"rankCode":"BBB+","life":7},
            {"defaultRate":0.1152,"rankCode":"BBB","life":7},
            {"defaultRate":0.15,"rankCode":"BBB-","life":7},
            {"defaultRate":0.21,"rankCode":"BB+","life":7},
            {"defaultRate":0.3,"rankCode":"BB","life":7},
            {"defaultRate":0.42,"rankCode":"BB-","life":7},
            {"defaultRate":0.53,"rankCode":"B+","life":7},
            {"defaultRate":0.71,"rankCode":"B","life":7},
            {"defaultRate":0.87,"rankCode":"B-","life":7},
            {"defaultRate":0.97,"rankCode":"CCC","life":7},
            {"defaultRate":0.99,"rankCode":"CC","life":7},
            {"defaultRate":0.99,"rankCode":"C","life":7},
            {"defaultRate":1,"rankCode":"D","life":7},
            {"defaultRate":0.005,"rankCode":"AAA+","life":8},
            {"defaultRate":0.006,"rankCode":"AAA","life":8},
            {"defaultRate":0.007,"rankCode":"AAA-","life":8},
            {"defaultRate":0.011,"rankCode":"AA+","life":8},
            {"defaultRate":0.012,"rankCode":"AA","life":8},
            {"defaultRate":0.018,"rankCode":"AA-","life":8},
            {"defaultRate":0.03,"rankCode":"A+","life":8},
            {"defaultRate":0.035,"rankCode":"A","life":8},
            {"defaultRate":0.059,"rankCode":"A-","life":8},
            {"defaultRate":0.082,"rankCode":"BBB+","life":8},
            {"defaultRate":0.1279,"rankCode":"BBB","life":8},
            {"defaultRate":0.17,"rankCode":"BBB-","life":8},
            {"defaultRate":0.23,"rankCode":"BB+","life":8},
            {"defaultRate":0.33,"rankCode":"BB","life":8},
            {"defaultRate":0.46,"rankCode":"BB-","life":8},
            {"defaultRate":0.57,"rankCode":"B+","life":8},
            {"defaultRate":0.735,"rankCode":"B","life":8},
            {"defaultRate":0.9,"rankCode":"B-","life":8},
            {"defaultRate":0.99,"rankCode":"CCC","life":8},
            {"defaultRate":0.99,"rankCode":"CC","life":8},
            {"defaultRate":0.99,"rankCode":"C","life":8},
            {"defaultRate":1,"rankCode":"D","life":8},
            {"defaultRate":0.0065,"rankCode":"AAA+","life":9},
            {"defaultRate":0.0075,"rankCode":"AAA","life":9},
            {"defaultRate":0.0086,"rankCode":"AAA-","life":9},
            {"defaultRate":0.013,"rankCode":"AA+","life":9},
            {"defaultRate":0.014,"rankCode":"AA","life":9},
            {"defaultRate":0.02,"rankCode":"AA-","life":9},
            {"defaultRate":0.0345,"rankCode":"A+","life":9},
            {"defaultRate":0.04,"rankCode":"A","life":9},
            {"defaultRate":0.067,"rankCode":"A-","life":9},
            {"defaultRate":0.092,"rankCode":"BBB+","life":9},
            {"defaultRate":0.1382,"rankCode":"BBB","life":9},
            {"defaultRate":0.18,"rankCode":"BBB-","life":9},
            {"defaultRate":0.25,"rankCode":"BB+","life":9},
            {"defaultRate":0.36,"rankCode":"BB","life":9},
            {"defaultRate":0.5,"rankCode":"BB-","life":9},
            {"defaultRate":0.61,"rankCode":"B+","life":9},
            {"defaultRate":0.76,"rankCode":"B","life":9},
            {"defaultRate":0.91,"rankCode":"B-","life":9},
            {"defaultRate":0.99,"rankCode":"CCC","life":9},
            {"defaultRate":0.99,"rankCode":"CC","life":9},
            {"defaultRate":0.99,"rankCode":"C","life":9},
            {"defaultRate":1,"rankCode":"D","life":9},
            {"defaultRate":0.008,"rankCode":"AAA+","life":10},
            {"defaultRate":0.009,"rankCode":"AAA","life":10},
            {"defaultRate":0.0104,"rankCode":"AAA-","life":10},
            {"defaultRate":0.015,"rankCode":"AA+","life":10},
            {"defaultRate":0.0175,"rankCode":"AA","life":10},
            {"defaultRate":0.0235,"rankCode":"AA-","life":10},
            {"defaultRate":0.038,"rankCode":"A+","life":10},
            {"defaultRate":0.0452,"rankCode":"A","life":10},
            {"defaultRate":0.0721,"rankCode":"A-","life":10},
            {"defaultRate":0.1,"rankCode":"BBB+","life":10},
            {"defaultRate":0.1462,"rankCode":"BBB","life":10},
            {"defaultRate":0.2,"rankCode":"BBB-","life":10},
            {"defaultRate":0.27,"rankCode":"BB+","life":10},
            {"defaultRate":0.38,"rankCode":"BB","life":10},
            {"defaultRate":0.53,"rankCode":"BB-","life":10},
            {"defaultRate":0.64,"rankCode":"B+","life":10},
            {"defaultRate":0.78,"rankCode":"B","life":10},
            {"defaultRate":0.92,"rankCode":"B-","life":10},
            {"defaultRate":0.99,"rankCode":"CCC","life":10},
            {"defaultRate":0.99,"rankCode":"CC","life":10},
            {"defaultRate":0.99,"rankCode":"C","life":10},
            {"defaultRate":1,"rankCode":"D","life":10}
        ];

        // 信用评级顺序
        const rankCodes = [
            "AAA+", "AAA", "AAA-", "AA+", "AA", "AA-", 
            "A+", "A", "A-", "BBB+", "BBB", "BBB-", 
            "BB+", "BB", "BB-", "B+", "B", "B-", 
            "CCC", "CC", "C", "D"
        ];

        // 初始化表格
        function initializeTable() {
            const tableBody = document.getElementById('tableBody');
            tableBody.innerHTML = '';
            
            // 获取所有期限
            const lives = [...new Set(defaultRateData.map(item => item.life))].sort((a, b) => a - b);
            
            lives.forEach(life => {
                const row = document.createElement('tr');
                const lifeCell = document.createElement('td');
                lifeCell.textContent = life;
                lifeCell.style.fontWeight = 'bold';
                row.appendChild(lifeCell);
                
                rankCodes.forEach(rankCode => {
                    const cell = document.createElement('td');
                    const data = defaultRateData.find(item => item.life === life && item.rankCode === rankCode);
                    cell.textContent = data ? data.defaultRate.toFixed(4) : '-';
                    row.appendChild(cell);
                });
                
                tableBody.appendChild(row);
            });
        }

        function findlifeAndCurrentCode(life,rankCode){
            return defaultRateData.find(item => item.life === life && item.rankCode === rankCode).defaultRate;
        }

        function portfolioRating(defaultRateData,weightedAverageMaturity, war,interpolatedDefaultRate) {
            let result = 0;
            const floor = Math.floor(weightedAverageMaturity);
            const ceil = Math.ceil(weightedAverageMaturity);
            let rdp = 0;
            while (true) {
                // 处理账龄 <= 1年的情况
                if (weightedAverageMaturity <= 1) {
                    rdp = defaultRateData[0].defaultRate * weightedAverageMaturity;
                } else {
                    const dr_l = findlifeAndCurrentCode(floor,rankCodes[result]);
                    const dr_u = findlifeAndCurrentCode(ceil,rankCodes[result]);
                    if (dr_l === dr_u) {
                        rdp = dr_l;
                    } else {
                        rdp = dr_l + (weightedAverageMaturity - floor) * (dr_u - dr_l) * 0.000001 * 1000000 / (ceil - floor);
                    }
                }

                if (rdp > war || result >= 12) {
                    break;
                }
                result++;
            }
            return {
                closestRank: rankCodes[result],
                interpolatedDefaultRate: rdp
            };
        }

        // 获取前一个评级
        function getPreviousRank(rank) {
            const index = rankCodes.indexOf(rank);
            if (index > 0) {
                return rankCodes[index - 1];
            }
            return rank; // 如果是第一个评级，返回自身
        }

        // 根据期限和评级获取违约率
        function getDefaultRate(life, rankCode) {
            const data = defaultRateData.find(item => item.life === life && item.rankCode === rankCode);
            return data ? data.defaultRate : null;
        }

        // 计算插值违约率
        function calculateInterpolatedDefaultRate(life, defaultRateValue) {
            const floor = Math.floor(life);
            const ceil = Math.ceil(life);
            let interpolatedDefaultRate=0;
            // 找到对应的评级
            const result = portfolioRating(defaultRateData,life, defaultRateValue,interpolatedDefaultRate);
            interpolatedDefaultRate = result.interpolatedDefaultRate;
            closestRank = result.closestRank;
            const previousRank = getPreviousRank(closestRank);
            const rankConcatenation = previousRank + "/" + closestRank;
            
            // 获取上下限期限的违约率
            const dr_l = getDefaultRate(floor, closestRank);
            const dr_u = getDefaultRate(ceil, closestRank);
            
            return {
                floorLife: floor,
                ceilLife: ceil,
                floorDefaultRate: dr_l !== null ? dr_l : defaultRateValue,
                ceilDefaultRate: dr_u !== null ? dr_u : defaultRateValue,
                interpolatedDefaultRate: interpolatedDefaultRate,
                correspondingRank: closestRank,
                rankConcatenation: rankConcatenation
            };
        }

        // 更新计算结果
        function updateResults() {
            const life = parseFloat(document.getElementById('life').value);
            const defaultRateValue = parseFloat(document.getElementById('defaultRateValue').value);
            
            const result = calculateInterpolatedDefaultRate(life, defaultRateValue);
            
            // 更新显示
            document.getElementById('floorLife').textContent = result.floorLife;
            document.getElementById('ceilLife').textContent = result.ceilLife;
            document.getElementById('floorDefaultRate').textContent = result.floorDefaultRate !== null ? result.floorDefaultRate.toFixed(4) : '无数据';
            document.getElementById('ceilDefaultRate').textContent = result.ceilDefaultRate !== null ? result.ceilDefaultRate.toFixed(4) : '无数据';
            document.getElementById('interpolatedDefaultRate').textContent = result.interpolatedDefaultRate.toFixed(4);
            document.getElementById('correspondingRank').textContent = result.correspondingRank;
            document.getElementById('rankConcatenation').textContent = result.rankConcatenation;
            
            // 高亮表格中的相关行
            highlightTableRows(result.floorLife, result.ceilLife);
        }

        // 高亮表格中的相关行
        function highlightTableRows(floor, ceil) {
            const tableRows = document.querySelectorAll('#tableBody tr');
            
            tableRows.forEach(row => {
                row.classList.remove('highlight');
                const lifeCell = row.cells[0];
                if (lifeCell && (parseInt(lifeCell.textContent) === floor || parseInt(lifeCell.textContent) === ceil)) {
                    row.classList.add('highlight');
                }
            });
        }

        // 初始化
        document.addEventListener('DOMContentLoaded', function() {
            initializeTable();
            
            document.getElementById('calculateBtn').addEventListener('click', updateResults);
            
            // 初始计算一次
            updateResults();
        });
    </script>

</body></html>